<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // promise-race--竞争  哪个异步操作先完成用哪个
      const p1 = () => {
        return new Promise((resolve, reject) => {
          setTimeout(() => {
            resolve('P1成功的数据')
          }, 5000)
        })
      }
      const p2 = () => {
        return new Promise((resolve, reject) => {
          setTimeout(() => {
            resolve('P2成功的数据')
          }, 8000)
        })
      }
      // Promise.race() 竞争请求  哪个异步操作先完成用哪个
      // 备用接口
      Promise.race([p1(), p2()]).then(value => {
        console.log(value)
      })
    </script>
  </body>
</html>
